// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import QtDesktop 0.1
import ".."
import "../delegates"
import "../models"
import "../views"

Rectangle {
    id: calendarWidget
    Utils {
        id: utils
    }

    property int dateInSeconds: monthCalendarModel.dateInSeconds
    property int day: monthCalendarModel.day
    property int month: monthCalendarModel.month
    property int year: monthCalendarModel.year

    signal dateChanged

    width: 190
    height: 210
    border.width: 1
    border.color: "lightgray"
    radius: 3
    Column {
        spacing: 0
        x: 5
        y: 5
        Row {
            spacing: 5
            Rectangle {
                id: month;
                width: 115
                height: parent.height

                Rectangle {
                    anchors.left: parent.left
                    width: 20
                    height: parent.height
                    Image {
                        anchors.fill: parent
                        source: "../../images/arrow-left.png"
                    }
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            monthCalendarModel.month = monthCalendarModel.month - 1
                        }
                    }
                }

                Text {
                    anchors.centerIn: parent
                    text: utils.getMonthName(monthCalendarModel.month)
                }

                Rectangle {
                    anchors.right: parent.right
                    width: 20
                    height: parent.height
                    Image {
                        anchors.fill: parent
                        source: "../../images/arrow-right.png"
                    }
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            monthCalendarModel.month = monthCalendarModel.month + 1
                        }
                    }
                }
            }
            SpinBox {
                width: 60
                value: monthCalendarModel.year
                maximumValue: 2100
                minimumValue: 0
                font.pixelSize: 12
                onValueChanged: {
                    if(monthCalendarModel.year !== value)
                        monthCalendarModel.year = value
                }
            }
        }
        Rectangle {
            width: 185
            height: 165
            MonthCalendar {
                anchors.fill: parent
                model: monthCalendarModel
                onDateChanged: {
                    if(currentIndex >= 0) {
                        var m = currentItem.m
                        var d = currentItem.d
                        monthCalendarModel.month = m
                        monthCalendarModel.day = d
                    }
                    calendarWidget.dateChanged()
                }
            }
        }
    }
}
